<?php
require_once ('./Model/ArticleModel.php');
require_once ('./View/ArticleView.php');
require_once ('./Model/DBSettings.php');


class ArticleController{
	private $articleModel;
	private $articleView;	
	/*
	 * Tar emot $action som inparameter och returnerar alla artiklar eller enskild artikel
	 * 
	 * @return string HTML
	 */	
	public function DoControll($action){
		$db = new mysqli(DBSettings::$host, DBSettings::$user, DBSettings::$password, DBSettings::$database);
		
		$this->articleModel = new ArticleModel($db);
		$this->articleView = new ArticleView();		
		
		switch ($action) {
			case Action::SHOW_NEWS:
				return $this->ShowNews();
				break;			
			default:
				return $this->ShowArticle();
				break;					
		}
	}
	//returnerar alla artiklar
	public function ShowNews(){
		return $this->articleView->DoArticleBox($this->articleModel->GetArticleArray());
	}
	//returnerar enskild artikel om sådan finns, annars returneras alla artiklar
	public function ShowArticle(){
		if(($articleId = $this->articleView->GetArticleId()) != null){
			return $this->articleView->DoArticleBox($this->articleModel->GetArticle($articleId));
		}
		return $this->articleView->DoArticleBox($this->articleModel->GetArticleArray());
	}
}
?>